 //本地存储一些购物车的数据防止刷新导致数据丢失
 import $store from './../../store';

 function storageCar() {
   if ($store.state.buyTicket.carTicketSumList.length === 0) {
     let storageCarUcan = JSON.parse(sessionStorage.getItem('storageCarUcan')) || {};
     $store.state.buyTicket.carTicketList = storageCarUcan.carTicketList || [];
     $store.state.buyTicket.carTicketSumList = storageCarUcan.carTicketSumList || [];
     $store.state.buyTicket.totalPrice = storageCarUcan.totalPrice || 0;
     $store.state.buyTicket.actualPrice = storageCarUcan.actualPrice || 0;
   } else {
     let storageCarUcan = {
       carTicketList: $store.state.buyTicket.carTicketList,
       carTicketSumList: $store.state.buyTicket.carTicketSumList,
       totalPrice: $store.state.buyTicket.totalPrice,
       actualPrice: $store.state.buyTicket.actualPrice
     };
     sessionStorage.setItem('storageCarUcan', JSON.stringify(storageCarUcan));
   }

   //  存储限购数量，
   if ($store.state.buyTicket.limitNum) {
     sessionStorage.setItem("storageLimitNum", $store.state.buyTicket.limitNum);
   } else {
     $store.state.buyTicket.limitNum = Number(sessionStorage.getItem("storageLimitNum") || 1);
   }

   //  存储团购邮件
   if ($store.state.buyTicket.connectEmail) {
     sessionStorage.setItem("storageconnectEmail", $store.state.buyTicket.connectEmail);
   } else {
     $store.state.buyTicket.connectEmail = sessionStorage.getItem("storageconnectEmail") || "";
   }

   //  存储门票状态
   if (JSON.stringify($store.state.buyTicket.getTicketState) != "{}") {
     sessionStorage.setItem("getTicketState", JSON.stringify($store.state.buyTicket.getTicketState));
   } else {
     $store.state.buyTicket.getTicketState = JSON.parse(sessionStorage.getItem("getTicketState"));
   }

   if ($store.state.buyTicket.groupBuyingLimitNum > 1) {
     sessionStorage.setItem("groupBuyingLimitNum", $store.state.buyTicket.groupBuyingLimitNum);
   } else {
     $store.state.buyTicket.groupBuyingLimitNum = sessionStorage.getItem("groupBuyingLimitNum") || 1;
   }




 }

 export {
   storageCar
 };
